package com.day1011.task;


import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class MyPanels extends JPanel {
    MapReader mapReader = new MapReader();
    BufferedImage[][] images = new BufferedImage[11][11];
    String[][] numArrays;
    {
        try {
            numArrays = mapReader.readMap();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public MyPanels(){
        for (int i = 0; i < numArrays.length; i++) {
            for (int j = 0; j < numArrays[i].length; j++) {
                File fileI = new File("F:\\task\\map0\\" + Integer.parseInt(numArrays[i][j]) + ".png");
                try {
                    images[i][j] = ImageIO.read(fileI);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    @Override
    public void paint(Graphics g) {
        for (int i = 0; i < numArrays.length; i++) {
            for (int j = 0; j < numArrays[i].length; j++) {
                g.drawImage(images[i][j],72 * j,72 * i,images[i][j].getWidth(),images[i][j].getHeight(),null);
            }
        }
    }
}
